package com.fzb.forum4j.service.impl;

import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.fzb.forum4j.dao.api.IArticleDao;
import com.fzb.forum4j.dao.api.ICommentDao;
import com.fzb.forum4j.po.Article;
import com.fzb.forum4j.po.Category;
import com.fzb.forum4j.po.QueryMode;
import com.fzb.forum4j.service.api.IArticleService;
import com.fzb.forum4j.service.api.ICommentService;
@Service("articleServiceImpl")
public class ArticleServiceImpl extends BaseServiceImpl<Article> implements
		IArticleService {

	@Resource(name="articleDaoImpl")
	private IArticleDao articleDao;
	@Resource(name="commentDaoImpl")
	private ICommentDao commentDao;
	
	@Resource(name="commentServiceImpl")
	private ICommentService commentService;
	@Override
	public void getInitData(QueryMode<Article> qmd,Set<Category> categories) {
		for (Category category : categories) {
			qmd.getT().setCategory(category);
			category.setCategoryName(articleDao.loadCategoryByCatalog(qmd.getT().getCategory().getCatalog()).getCategoryName());
			articleDao.getInitData(qmd);
		}
	}
	@Override
	public void getEntityByEid(QueryMode<Article> qmd) {
		articleDao.getEntityByEid(qmd);
	}
	@Override
	public void getList(QueryMode<Article> qmd) {
		if(qmd.getT()!=null){
			if(qmd.getT().getCategory()!=null){
				qmd.getData().put("category", qmd.getT().getCategory().getCatalog());
			}
		}
		
		articleDao.getList(qmd);
	}
	@Override
	public void getArticleAndComment(QueryMode<Article> qmd) {
		articleDao.getEntityByEid(qmd);
		commentService.getCommentsByCid(qmd);
	}
	@Override
	public void getArticlesByQmd(QueryMode<Article> qmd) {
		if(qmd.getKeyword()!=null){
			qmd.getT().setKeywords("%"+qmd.getKeyword()+"%");
			articleDao.getArticleByKeywrod(qmd);
		}
		
	}
	@Override
	public void updateArticlesViews(Map<String, Integer> map) {
		articleDao.updateArticleView(map);
	
	}
	

}
